package com.sfzy.controller;

import com.sfzy.service.CourseCollectService;
import com.sfzy.entity.CourseCollect;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("courseCollect")
public class CourseCollectController {
    @Autowired
    private CourseCollectService courseCollectService;

    @PostMapping
    public R addCourseCollect(@RequestBody CourseCollect courseCollect) {
        return R.ok(courseCollectService.addCourseCollect(courseCollect));
    }

    @GetMapping("{id}")
    public R getCourseCollect(@PathVariable("id") int id) {
        return R.ok(courseCollectService.getCourseCollectById(id));
    }

    @DeleteMapping("{id}")
    public R deleteCourseCollect(@PathVariable("id") int id) {
        return R.ok(courseCollectService.deleteCourseCollect(id));
    }

    @PutMapping
    public R updateCourseCollect(@RequestBody CourseCollect courseCollect) {
        return R.ok(courseCollectService.updateCourseCollect(courseCollect));
    }

    @GetMapping("page3")
    public R getCourseCollectPage(CourseCollect courseCollect,
                                  @RequestParam(required = false,defaultValue = "1") int pageNum,
                                  @RequestParam(required = false,defaultValue = "6") int pageSize) {
        return R.ok(courseCollectService.getAllCourseCollectByPage3(courseCollect,pageNum,pageSize));
    }
}
